package com.kede.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kede.domain.SuppliesStoreDomain;
import com.kede.service.SuppliesStoreService;
import com.kede.mapper.SuppliesStoreMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
* @author 11856
* @description 针对表【t_supplies_store(物资门店关联表)】的数据库操作Service实现
* @createDate 2023-06-07 11:25:38
*/
@Service
public class SuppliesStoreServiceImpl extends ServiceImpl<SuppliesStoreMapper, SuppliesStoreDomain>
    implements SuppliesStoreService{

    @Override
    public boolean setInvetory(Integer storeId, Integer supplieId, Integer symbolnum) {
        LambdaQueryWrapper<SuppliesStoreDomain> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SuppliesStoreDomain::getStoreId,storeId);
        queryWrapper.eq(SuppliesStoreDomain::getSupplieId,supplieId);
        SuppliesStoreDomain one = getOne(queryWrapper);
        one.setCurrNum(one.getCurrNum() + symbolnum);
        one.setUpdateTime(LocalDateTime.now());
        one.setUpdateBy("api-order");
        return updateById(one);
    }

    @Override
    public int getInvetory(Integer storeId, Integer supplieId) {
        LambdaQueryWrapper<SuppliesStoreDomain> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SuppliesStoreDomain::getStoreId,storeId);
        queryWrapper.eq(SuppliesStoreDomain::getSupplieId,supplieId);
        SuppliesStoreDomain one = getOne(queryWrapper);
        return  one.getCurrNum();
    }
}




